<template>
    <div class="login">
       <div class="login-box" v-if="auth_code==''">
   
         <!--   <div class="sub-title font-14">抽奖大转盘电脑端</div>-->

            </div>
        </div>
    </div>
</template>

<script>
import { postAuthLogin } from "../api/login";	
import Cookies from "js-cookie";

export default {
  name: 'index',
   components: {

  },
  data () {
    return {
    	qrCode:'',
     	auth_code:'',
     	isSending:false,
    }
  },
  methods:{
  	   	//领取裂变券
   	fnPostAuthLogin(){
   		if(this.isSending == true){
   			console.log('请稍等');
   			return false;
   		}
   		var params = {
        auth_code:this.auth_code
      }
   		this.isSending = true;
   		postAuthLogin(params
     ).then((res) => {
     
      	this.isSending = false;
        let { msg, code, data } = res.data;
        
        if(code == 200){
      		if(data && data.token){
	        	this.token = data.token;
	     		Cookies.set('token',data.token,{ expires: 7 });
	     		console.log('登录成功');
	     		location.href="/#/userinfo"
	        }
	        else{
	        	this.$message.error(msg);
	      	 	location.href="/#/login"
	        	console.log(msg)
	        }
      	}
      	else{
      		this.$message.error(msg);
	      	location.href="/#/login"
	        console.log(msg)
      	}
      	

        
        
      },reject=>{
      	 this.isSending = false;
      	 let { message, code, data } = reject;
      	 this.$message.error(message);
      	 location.href="/#/login"
      	 
      });
   	},
  	
  },
  created(){
  	 
  	  this.auth_code = this.$route.query.auth_code || location.search.split("?auth_code=")[1].split("#/")[0];
  	  this.token = Cookies.get('token');
  	  if(this.auth_code){
  	  	console.log('去登录');
	    this.fnPostAuthLogin()
  	  }
  	  else{
  		location.href="/#/"
//	  	this.$router.push('/')
  	  }
	
  },
  mounted(){

  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped  type="text/scss" lang="scss" >

	.login {
	    width: 100vw;
	    height: 100vh;
	    position: relative;
	    background-image: url('~@/assets/image/background2.svg');
	    background-size: 100%;
	    .login-box {
	        position: absolute;
	        top: 50%;
	        left: 50%;
	        transform: translate(-50%, -50%);
	        width: 400px;
	        height: 480px;
	        background-color: #ffffff;
	        box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.16);
	        text-align: center;
	        .title {
	            padding-top: 40px;
	            img {
	                width: 48px;
	                height: 48px;
	                margin-right: 15px;
	            }
	        }
	        .sub-title {
	            padding-top: 15px;
	        }
	        .code-login {
	            padding-top: 20px;
	            .qr-code {
	                position: relative;
	                width: 160px;
	                margin: 30px auto 0;
	                .expire {
	                    flex-direction: column;
	                    color: #fff;
	                    position: absolute;
	                    top: 0;
	                    left: 0;
	                    right: 0;
	                    bottom: 0;
	                    background-color: rgba(0, 0, 0, 0.7);
	                    .icon {
	                        width: 28px;
	                        height: 28px;
	                    }
	                    p {
	                        margin-top: 10px;
	                    }
	                }
	            }
	        }
	    }
	}
</style>
